import 'package:flutter/foundation.dart';
import 'package:dio/dio.dart';
import 'package:body_measurement/common/http_interceptor.dart';

class MeyHttpUtil {
  final baseUrl = 'http://114.55.25.10:8181';
  late Dio _dio;
  static final MeyHttpUtil _instance = MeyHttpUtil._internal();

  factory MeyHttpUtil() {
    return _instance;
  }

  MeyHttpUtil._internal() {
    _dio = Dio(BaseOptions(baseUrl: baseUrl));
    _dio.interceptors.add(LogInterceptor(requestBody: true));
    _dio.interceptors.add(MeyHttpInterceptor());
  }

  Future<Response?> get(String url, {Map<String, dynamic>? params}) async {
    try {
      return await _dio.get(url, queryParameters: params);
    } on DioException catch (e) {
      debugPrint(e.message);
      return null;
    } catch (e) {
      debugPrint(e.toString());
      return null;
    }
  }
}
